package com.dongbo.recorder.screenrecord.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
 * RecyclerView ->Adapter
 *
 * @param <VH>
 */
public abstract class BaseRVAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {

    protected String TAG = BaseRVAdapter.class.getName();


    protected int lastCheck = -1;
    private LayoutInflater mLayoutInflater;


    protected LayoutInflater getLayoutInflater(Context context) {
        if (null == mLayoutInflater) {
            mLayoutInflater = LayoutInflater.from(context);
        }
        return mLayoutInflater;
    }


    /**
     * 被选中的项的下标
     */
    public int getChecked() {
        return lastCheck;
    }

    /**
     * 是否允许重复点击
     *
     * @param enableRepeatClick
     */
    public void setEnableRepeatClick(boolean enableRepeatClick) {

        this.enableRepeatClick = enableRepeatClick;
    }

    protected boolean enableRepeatClick = false;


    /**
     * 设置单击事件
     */
    public void setOnItemClickListener(OnItemClickListener listener) {
        mOnItemClickListener = listener;
    }


    protected OnItemClickListener mOnItemClickListener;

    /**
     * 查找容器范围内的组件
     */
    protected <T extends View> T $(View mRoot, int resId) {
        return mRoot.findViewById(resId);
    }

    /**
     * item单击事件
     */
    protected class BaseItemClickListener implements View.OnClickListener {

        protected int position;

        public void setPosition(int position) {
            this.position = position;
        }

        @Override
        public void onClick(View v) {

        }
    }

}
